package com.buaa.utility.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Login extends HttpServlet implements Servlet {
	private String loginPage;
	
	public Login() {
		super();
	}
	
	public void init() throws ServletException {
		loginPage = this.getInitParameter("loginPage");
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		try {
			execute(request, response);
		} catch (Exception e) {
			throw new ServletException(e);
		}
	}
	
	private void execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception, ServletException{
		String userId = request.getParameter("username");
		System.out.println("userId:" + userId);
		if(userId.equals("superadmin")){
			request.setAttribute("userId", userId);
			request.getRequestDispatcher("./product/products1.jsp").forward(request, response);
		}
		request.setAttribute("userId", userId);
		request.getRequestDispatcher("./product/products1.jsp").forward(request, response);
	}
	
}